home *** CD-ROM | disk | FTP | other *** search
- Path: swidir.switch.ch!epflnews!Thomas.Wolf
- From: Thomas.Wolf@di.epfl.ch (Thomas Wolf)
- Newsgroups: comp.lang.c
- Subject: Re: Help
- Date: 11 Apr 1996 08:00:34 GMT
- Organization: Ecole Polytechnique FΘdΘrale de Lausanne
- Sender: wolf@lglsun5.epfl.ch (Thomas Wolf)
- Message-ID: <4kie72$djg@info.epfl.ch>
- References: <316C3043.A5D@hlp.com>
- NNTP-Posting-Host: lglsun5.epfl.ch
-
- In article <316C3043.A5D@hlp.com>, andrew kennedy <"andrew kennedy"@hlp.com> writes:
- :>
- :> I wrote this code early in my C career, but there should be a better to
- :> do this. Can someone help.
- :>
- [Snip]
-
- Although it's not hard to figure out, it would have been nice if you'd
- given a short description of what your code was supposed to do.
-
- Anyway, look up the 'strrchr' function in the standard library. Using
- it greatly simplifies your task:
-
- #include <string.h>
-
- ...
-
- void set_suffix (char *original, char *suffix, char *new)
- {
- char *p;
-
- strcpy (new, original);
- p = strrchr (new, '.');
- if (p && p != new) *p = '\0';
- strcat (new, suffix);
- }
-
- (The "p != new" part handles cases like ".cshrc" correctly - I suppose
- you'd want such a file name to become ".cshrc.enc", not ".enc"...
- The 'suffix' is supposed to start with a dot.)
-
- Regards,
-
- Thomas
- ----------------------------------------------------------------------
- Swiss Federal Institute of Technology | Thomas Wolf
- Software Engineering Laboratory | EPFL-DI-LGL
- Thomas Wolf (TW) | CH-1015 Lausanne (Suisse)
- E-Mail: wolf@di.epfl.ch | Phone: (++41 21)693 42 37
- ----------------------------------------------------------------------
-
-